package beanstao.util.collections.set$range;

import beanstao.util.Strings;
import beanstao.util.Util;

public class FloatSet
{

	public static FloatSet make(String s)
	{
		if (s.length() < 3)
		{
			throw Util.makeThrow("Invalid FloatSet : '%s'", s);
		}
		s = Strings.trim(s);
		char l = s.charAt(0);
		char r = s.charAt(s.length() - 1);
		FloatRange ir = FloatRange.make(s.substring(1, s.length() - 1));

		return new FloatSet(l, r, ir);
	}

	private final char l;
	private final char r;
	private final FloatRange ir;

	private FloatSet(char l, char r, FloatRange ir)
	{
		this.l = l;
		this.r = r;
		this.ir = ir;
	}

	public boolean match(float n)
	{
		// [left : right]
		if ((this.l == '[') && (this.r == ']'))
		{
			return this.ir.inon(n);
		}
		// (left : right)
		else if ((this.l == '(') && (this.r == ')'))
		{
			return this.ir.in(n);
		}
		// [left : right)
		else if (this.l == '[')
		{
			return this.ir.linon(n);
		}
		// (left : right]
		return this.ir.rinon(n);
	}

	@Override
	public String toString()
	{
		return new StringBuilder().append(this.l).append(this.ir.toString()).append(this.r).toString();
	}

}
